#include"HashEntry.h"
const int TABLE_SIZE = 128;

template <class T>
class HashMap
{
private:
	HashEntry<T> **table;
public:
	HashMap()
	{
		table = new HashEntry<T>*[TABLE_SIZE];
		for (int i = 0; i < TABLE_SIZE; i++)
		{
			table[i] = NULL;
		}
	}
	int get(int key)
	{
		int hash = (key % TABLE_SIZE);
		return table[hash]->getValue();
	}
	void put(int key, T value)
	{
		int hash = (key % TABLE_SIZE);
		while(table[hash] != NULL && table[hash]->getValue() != key)
			hash = (hash + 1) % TABLE_SIZE;
		if(table[hash]!=NULL)
			delete table[hash];
		table[hash] = new HashEntry<T>(key, value);
	}
	~HashMap()
	{
		for (int i = 0; i < TABLE_SIZE; i++)
		{
			if(table[i] != NULL)
				delete table[i];		
		}
		delete[] table;
	}
};